package mysql

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"yukao1/conf"
	"yukao1/models/global"
)

func InitMysql() {
	err := global.Err
	res := conf.AppData.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		res.Name, res.Pwd, res.Head, res.Port, res.Dbname)
	global.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println("数据库链接失败", err)
		return
	}
	fmt.Println("数据库链接成功", res)
	global.DB.AutoMigrate(&UserYk{}, &OrderYk{})
	fmt.Println("1")
	global.DB.AutoMigrate(OrderDetailYk{}, GoodsYk{})
	fmt.Println("2")
}
